package com.yidu.t299.dao.ssk;
import com.yidu.t299.domain.ssk.Account;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * @author 粟术康
 * @version 1.0
 * @description
 * @date:2023/3/7 11:41
 */
@Mapper
public interface AccountMapper {
    /**
     * 添加账户信息
     * @param account 账户对象
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({"insert into account (account_remark, account_type,account_id)" +
            " values (#{accountRemark,jdbcType=VARCHAR}, #{accountType,jdbcType=VARCHAR},#{accountId,jdbcType=INTEGER})"
    })
    int insert(Account account);
    /**
     * 根据账户编号删除该账户信息
     * @param accountId 账户编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({"delete from account" +
            " where account_id = #{accountId,jdbcType=INTEGER}"})
    int deleteByPrimaryKey(Integer accountId);
    /**
     * 根据账户信息修改其数据
     * @param account 账户对象
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update account" +
            " set account_remark = #{accountRemark,jdbcType=VARCHAR}," +
            " account_type = #{accountType,jdbcType=VARCHAR}"+
            " where account_id = #{accountId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Account account);
    /**
     * 根据账户编号查询指定的信息
     * @param accountId 账户编号
     * @return 账户对象
     */
    @Select({
            "select" +
                    " account_remark, account_type","account_id" +
                    " from account" +
                    " where account_id = #{accountId,jdbcType=INTEGER}"
    })
    @Results(id = "AccountMap",value = {
            @Result(column = "account_remark",property = "accountRemark"),
            @Result(column = "account_type",property = "accountType"),
            @Result(id = true,column = "account_id",property = "accountId" )
    })

    Account selectByPrimaryKey(Integer accountId);

    /**
     * 按条件分页查询账户数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 账户对象集合
     */
    @Select("select * from account where 1=1 ${condition} limit #{page},#{rows}")
    @ResultMap("AccountMap")
    List<Account> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询account表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from account where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);
}
